/**
 *	Copyright (c) 2009, SpLib.net
 * 	All rights reserved.
  	
 * 	Author:6spring
 * 	About:16进制编解码
*/

package SpLib.Tools
{
	import com.hurlant.util.Hex;
	import flash.utils.ByteArray;
	
	public class Hex
	{
		public function Hex()
		{
		}
		
		/**
		 * Hex编码，字符串
		*/
		public static function encode(data:String,charset:String):String
		{
			var bytes:ByteArray = new ByteArray();
			bytes.writeMultiByte(data,charset);
			return com.hurlant.util.Hex.fromArray(bytes);
		}
		
		/**
		 * Hex编码，数组
		*/
		public static function encodeByteArray(bytes:ByteArray):String
		{
			return com.hurlant.util.Hex.fromArray(bytes);
		}
		
		/**
		 * Hex解码，字符串
		*/
		public static function decode(str:String,charset:String):String
		{
			var bytes:ByteArray = com.hurlant.util.Hex.toArray(str);
			return bytes.readMultiByte(bytes.length,charset);
		}
		
		/**
		 * Hex解码，数组
		*/
		public static function decodeByteArray(str:String):ByteArray
		{
			return com.hurlant.util.Hex.toArray(str);
		}

	}
}